package ml

import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.sql.SparkSession

object Person {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder()
      .appName("app")
      .master("local[*]")
      .getOrCreate()
    import spark.implicits._
    val context = spark.read
      .format("libsvm")
      .load("spark/data/人体指标.txt")
    val srcDF = context.toDF()
    srcDF.groupBy("label").count().show()

    val Array(train, test) = srcDF.randomSplit(Array(0.8, 0.2))
    val regression = new LogisticRegression()
    val model = regression.fit(train)
    val trans = model.transform(test)
    trans.filter($"label" =!= $"prediction").show()
    model.save("spark/data/models/person_model")
  }

}
